package edu.hitsz.shootStrategy;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.HeroAircraft;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;
import edu.hitsz.bullet.HeroBullet;

import java.util.LinkedList;
import java.util.List;

public class ShootDirect implements ShootStrategy{
    @Override
    public List<BaseBullet> doShoot(AbstractAircraft abstractAircraft) {
        int direction=abstractAircraft.getDirection();
        int power=abstractAircraft.getPower();
        int shootNum=1;

        //获取当前飞机位置，确定子弹生成位置
        int x = abstractAircraft.getLocationX();
        int y = abstractAircraft.getLocationY() + direction*2;
        int speedX = 0;
        int speedY = abstractAircraft.getSpeedY() + direction*5;


        List<BaseBullet> res = new LinkedList<>();

        BaseBullet bullet;
        for(int i=0; i<shootNum; i++){
            // 多个子弹横向分散
            if(abstractAircraft instanceof HeroAircraft) {
                bullet = new HeroBullet(x + (i * 2 - shootNum + 1) * 10, y, speedX, speedY, power);
            }else {
                bullet = new EnemyBullet(x + (i * 2 - shootNum + 1) * 10, y, speedX, speedY, power);
            }

            res.add(bullet);
        }
        return res;
    }
}
